package com.tang.imgupload.config;

import com.tang.imgupload.commen.Constant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
	//绑定键,转发给SRCNN,调用SRCNN,在Constant中定义
	// 一个交换器，三个队列
	@Bean
	TopicExchange exchange(){
		return new TopicExchange(Constant.RABBIT_MQ.EXCHANG_SR.getValue());
	}

	@Bean
	public Queue SRMDQueue(){

		return new Queue(Constant.RABBIT_MQ.QUEUE_SRMD.getValue(), true);
	}

	@Bean
	public Queue BiCubicQueue(){
		return new Queue(Constant.RABBIT_MQ.QUEUE_BICUBIC.getValue(), true);
	}

	@Bean
	public Queue SRCNNQueue(){
		return new Queue(Constant.RABBIT_MQ.QUEUE_SRCNN.getValue(), true);
	}


	//将firstQueue和topicExchange绑定,而且绑定的键值为topic.man
	//这样只要是消息携带的路由键是topic.man,才会分发到该队列
	//将secondQueue和topicExchange绑定,而且绑定的键值为用上通配路由键规则topic.#
	// 这样只要是消息携带的路由键是以topic.开头,都会分发到该队列
	//*：表示一个词，#：表示零个或多个词
	@Bean
	Binding bindingExchangeMessage1(){
		return BindingBuilder.bind(SRMDQueue()).to(exchange()).with(Constant.RABBIT_MQ.QUEUE_SRMD.getValue());
	}

	@Bean
	Binding bindingExchangeMessage2(){
		return BindingBuilder.bind(BiCubicQueue()).to(exchange()).with(Constant.RABBIT_MQ.QUEUE_BICUBIC.getValue());
	}

	@Bean
	Binding bindingExchangeMessage3(){
		return BindingBuilder.bind(SRCNNQueue()).to(exchange()).with(Constant.RABBIT_MQ.QUEUE_SRCNN.getValue());
	}

}
